<template>
  <!-- 分包计量 -->
  <base-breadcrumb :title="$route.meta.title">
    <!-- 搜索 -->
    <searchData :searchData="searchArr" @search="search"></searchData>
    <!-- 表格 -->
    <a-card :bordered="false">
      <a-button class="mb12" icon="plus" type="primary" @click="handleManage(2)" v-btnPermission="'bm_010_add_01'">新增上报</a-button>
      <span style="display: inline-block; color: red; width: 1472px; text-align: right">注：云筑网已录入产值单的，本系统完善数据即可，无需重复新增。</span>
      <a-alert class="mb12" type="info" show-icon>
        <template slot="message">
          <span>
            本月分包上报值(含税)(万元)：
            <a>{{ statistics.includingTax }}</a>
          </span>
          <a-divider type="vertical" />
          <span>
            累计分包上报值(含税)(万元)：
            <a>{{ statistics.includingTaxTotal }}</a>
          </span>
          <a-divider type="vertical" />
          <span>
            累计罚款(万元)：
            <a>{{ statistics.penaltyMonthTotal }}</a> </span
          ><br />
          <span>
            本月确认产值(含税)(万元)：
            <a>{{ statistics.confirmIncludingTax }}</a>
          </span>
          <a-divider type="vertical" />
          <span>
            累计确认产值(含税)(万元)：
            <a>{{ statistics.totalIncludingTax }}</a>
          </span>
        </template>
      </a-alert>
      <!-- 表格 -->
      <list-table ref="table" size="default" rowKey="id" :columns="columns" :request="loadData" :alert="true" show-size-changer show-quick-jumper showPagination="auto">
        <template slot="action" slot-scope="text, record">
          <MoreButton>
            <a @click="handleManage(0, record)" v-btnPermission="'bm_010_loo_04'">查看</a>
            <span v-if="(record.status != 'SUBMITTED' && record.status != 'PAST' && record.status != 'ABOLISH') || record.isYun == 1" v-btnPermission="'bm_010_edi_02'">
              <a-divider type="vertical" />
              <a @click="handleManage(1, record)">编辑</a>
            </span>

            <span v-if="record.status == 'SUBMITTED'&&selfBtnShow(record.creatorId)&&hideBuquBtn()">
              <a-divider type="vertical" />
              <a @click="handleUndo({ id: record.id, type: 3 })">撤销</a>
            </span>
            <span v-if="record.status == 'PAST'" v-btnPermission="'bm_010_tov_05'">
              <a-divider type="vertical" />
              <a @click="handleInvalid({ id: record.id, type: 2 })">作废</a>
            </span>
            <!-- 删除 -->
            <span v-if="record.status == 'DRAFT' || record.status == 'REJECTED'" v-btnPermission="'bm_010_del_03'">
              <a-divider type="vertical"></a-divider>
              <a @click="handleRemoveParams({ id: record.id, type: 1 })">删除</a>
            </span>

            <span v-if="record.status === 'PAST' || record.status === 'SUBMITTED' || record.status === 'REJECTED' || record.status === 'ABOLISH'" v-btnPermission="'bm_010_loo_04'">
              <a-divider type="vertical" />
              <approval-button :id="record.id" :status="record.status" />
            </span>
          </MoreButton>
        </template>
        <template slot="status" slot-scope="text, record">
          <list-status v-if="record.status" :status="record.status" conversion="en" :is-approval="true" :text="text" />
          <span v-else>-</span>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { getSMListList, delSMList, getSMListStatistical } from '@/api/businessAffairs/SMList' // api
import BasePage from '@/views/basePage' // 基础配置
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import MoreButton from '@/components/MoreButton'
import { yunStatusList } from './model.js'
import { typeListApproval } from '@/utils/util.js'
import SelectSubcontractorCode from '@/components/Select/SelectSubcontractorCode' // 分包商
const searchArr = [
  // 搜索框
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  {
    name: '分包商',
    type: 'input',
    value: 'subContractUnitName'
  },
  {
    name: '分包合同名称',
    type: 'input',
    value: 'contractName'
  },
  {
    name: '计量月份',
    value: 'measureMonth',
    type: 'month'
  },
  {
    name: '状态',
    value: 'status',
    type: 'select',
    data: typeListApproval
  },
  {
    name: '云筑网状态',
    value: 'yunStatus',
    type: 'select',
    data: yunStatusList
  },
  {
    name: '填报人',
    type: 'input',
    value: 'creatorName'
  },
  {
    name: '填报时间',
    type: 'dateRange',
    value: 'activityDate',
    attr: {
      rangeFormat: ['createTimeBegin', 'createTimeEnd']
    }
  }
]
const columns = [
  {
    title: '产值单名称',
    dataIndex: 'outputName',
    ellipsis: true
  },
  {
    title: '所属分公司',
    dataIndex: 'branchComName',
    ellipsis: true
  },

  {
    title: '所属项目',
    dataIndex: 'projectName',
    ellipsis: true
  },
  {
    title: '分包商',
    dataIndex: 'subcontractorName',
    ellipsis: true
  },
  {
    title: '分包合同名称',
    dataIndex: 'contractName',
    ellipsis: true
  },
  {
    title: '计量月份',
    dataIndex: 'measureMonth',
    ellipsis: true
  },

  {
    title: '本月分包上报值(含税)(万元)',
    dataIndex: 'includingTax'
  },
  {
    title: '本月确认(含税)(万元)',
    dataIndex: 'confirmIncludingTax'
  },
  {
    title: '累计确认(含税)(万元)',
    dataIndex: 'totalIncludingTax'
  },
  {
    title: '本月罚款(含税)(万元)',
    dataIndex: 'penaltyMonth'
  },

  {
    title: '填报人',
    dataIndex: 'creatorName',
    ellipsis: true
  },
  {
    title: '填报时间',
    dataIndex: 'createTime'
  },
  {
    title: '云筑网状态',
    dataIndex: 'yunStatusStr',
    ellipsis: true,
    customRender() {
      return arguments[1].isYun == 1 ? arguments[1].yunStatusStr : '-'
    }
  },
  {
    title: '状态',
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '180px',
    align: 'center',
    fixed: 'right',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    STable,
    MoreButton,
    SelectSubcontractorCode
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数
      userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
      statistics: {
        confirmIncludingTax: 0,
        includingTax: 0,
        includingTaxTotal: 0,
        penaltyMonthTotal: 0,
        totalIncludingTax: 0
      }, //统计
      loadData: async (parameter) => {
        const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
        this.getSMListStatisticalReq(requestParameters)
        return getSMListList(requestParameters).then((res) => {
          return res
        })
      },
      removeApi: { remove: delSMList, invalid: delSMList, undo: delSMList } // api
    }
  },
  methods: {
    getSMListStatisticalReq(requestParameters) {
      getSMListStatistical(requestParameters).then((res) => {
        this.statistics = res.data
      })
    },
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    handleManage(type, record) {
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      if (record && record.yunStatus) {
         query.yunStatus = record.yunStatus
       }
      this.$router.push({
        name: 'updateSMList',
        query
      })
    }
  }
}
</script>
